<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="button" value="测试" onclick="fn01()">
    <!-- 选择排序 -->
    <script>
        function fn01() {
            var scores = [12, 54, 4, 8, 10];
            console.log(selectSort(scores));
        }
        function selectSort(arr) {
            for (var i = 0; i < arr.length; i++) {
                var min = arr[i];
                var index = i;
                for (var j = i + 1; j < arr.length; j++) {
                    if (arr[j] < min) {
                        min = arr[j];
                        index = j;
                    }
                }
                var temp = arr[i];
                arr[i] = arr[index];
                arr[index] = temp
            }
         return arr;
        }

    </script>
</body>

</html>